using System.Collections.Generic;
using UnityEngine;

namespace BCW.Friends
{
	public class FriendsUICategory : SelectableButtonController
	{
		public FriendInfoUI exampleTile;

		public UILabel searchLable;

		public bool findWebPlayer;

		private TouchScreenKeyboard mKeyboard;

		private string mText = string.Empty;

		public void Init(List<PlayerInfo> players)
		{
			FriendsUIMessageManager.instance.searchMessagePanel.HideLoading();
			if (players.Count == 0 && findWebPlayer)
			{
				FriendsUIMessageManager.instance.searchMessagePanel.ShowMessageWindow();
			}
			Dictionary<string, uint> countNewMessages = FriendsController.instance.GetCountNewMessages();
			foreach (PlayerInfo player in players)
			{
				FriendInfoUI friendInfoUI = Object.Instantiate(exampleTile);
				uint unreadMesages = 0u;
				if (countNewMessages.ContainsKey(player.playerId))
				{
					unreadMesages = countNewMessages[player.playerId];
				}
				friendInfoUI.transform.parent = grid.transform;
				friendInfoUI.transform.localScale = Vector3.one;
				friendInfoUI.transform.position = Vector3.zero;
				friendInfoUI.Init(player, unreadMesages);
				AddNewButton(friendInfoUI);
				friendInfoUI.gameObject.SetActive(true);
			}
			grid.enabled = true;
		}

		public void RemoveButtons(List<SelectableButton> listButtons)
		{
			allButtons.RemoveAll((SelectableButton x) => listButtons.Contains(x));
			foreach (SelectableButton listButton in listButtons)
			{
				Object.Destroy(listButton.gameObject);
			}
			grid.enabled = true;
		}

		public void FindPlayer()
		{
			findWebPlayer = true;
			FriendsUIMessageManager.instance.searchMessagePanel.ShowLoading();
			ClearAllButtons();
			FriendsController.instance.FindPlayer(searchLable.text, Init);
		}
	}
}
